#include "RsGisLibEleHillShade.h"
#include "ExtensionManager.h"
#include "ExtensionSession.h"
#include <QVariant>

RsGisLibEleHillShade::RsGisLibEleHillShade(RsgisPortal* ClientPortal, QWidget *parent)
{
	ui = new Ui::RsGisLibEleHillShade();
	ui->setupUi(this);

	Portal = ClientPortal;

	connect(ui->pushButton_InputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_InputFilePath_clicked()));
	connect(ui->pushButton_OutputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_OutputFilePath_clicked()));
	connect(ui->pushButton_CalHillShade, SIGNAL(clicked()), this, SLOT(on_action_Button_CalHillShade_clicked()));

	ui->textBrowser_ParameterDescription->setText(
		"azimuth - is a float with the solar azimuth in degrees (Good value is 315)\nzenith - is a float with the solar zenith in degrees(Good value is 45)\nGdal Format - string specifying the output image format"
	);

	ui->textBrowser_ParameterDescription->setEnabled(false);

	ui->lineEdit_InputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\srtm_61_06.img");
	ui->lineEdit_OutputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\TestHillShade");

	ui->lineEdit_GdalFormat->setText("GTIFF");
	ui->lineEdit_SolarAzimuth->setText("315");
	ui->lineEdit_SolarZenith->setText("45");

	ui->lineEdit_Priority->setText("16");
}

void RsGisLibEleHillShade::on_action_Button_InputFilePath_clicked()
{
	QString str = QFileDialog::getOpenFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_InputFilePath->setText(str.toUtf8());
}

void RsGisLibEleHillShade::on_action_Button_OutputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "Tif file(*.tif *.TIF);;All file(*.*)");
	ui->lineEdit_OutputFilePath->setText(str.toUtf8());
}

void RsGisLibEleHillShade::on_action_Button_CalHillShade_clicked()
{
	{
		if (ui->lineEdit_InputFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Input File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_OutputFilePath->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Output File Path is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if(ui->lineEdit_SolarAzimuth->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Solar Azimuth is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_SolarZenith->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Solar Zenith is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_GdalFormat->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Gdal Format is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}

		if (ui->lineEdit_Priority->text().isEmpty())
		{
			QMessageBox::warning(NULL, "Error", "Priority is Null", QMessageBox::Yes, QMessageBox::Yes);
			return;
		}
	}

	QList<QVariant> SysParaList;
	SysParaList << QVariant(QString("RsGisLib"));
	SysParaList << QVariant(QString("Elevation"));
	SysParaList << QVariant(int(ui->lineEdit_Priority->text().toInt()));

	QList<QVariant> AlgParaList;
	AlgParaList << QVariant(QString("HillShade"));
	AlgParaList << QVariant(QString(ui->lineEdit_InputFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_OutputFilePath->text()));
	AlgParaList << QVariant(double(ui->lineEdit_SolarAzimuth->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_SolarZenith->text().toDouble()));
	AlgParaList << QVariant(QString(ui->lineEdit_GdalFormat->text()));

	QVariantList ArgList;
	ArgList << (QVariant)SysParaList;
	ArgList << (QVariant)AlgParaList;

	Portal->goAhead(ArgList);
}